using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace xingzhimeng
{
  ///<summary>
  ///
  ///</summary>
public class Gun : MonoBehaviour
  {
      private float XMaxRotate = 70;
      private float XMinRotate = 0;
      private float YMinRotate = 0;
      private float YMaxRotate = 120;
      private float currentX;
      private float currentY;
      public float AtkTime = 1;
      private float time = 0;
      public Transform FirePoint;//子弹出生点
      public GameObject bullet;//子弹
      private Animation anima;
      public AudioClip fire;//开火声音
      public static AudioClip collSource;

      private void Start()
      {
          anima = GetComponent<Animation>();
          collSource = Resources.Load<AudioClip>("Sources/kick");
      }

      private void FixedUpdate()
      {
       //   time += Time.deltaTime;
          if (time > AtkTime)
          {
              if (Input.GetMouseButton(0))
              {
                  anima.Play();
               GameObject bull=   GameObject.Instantiate(bullet, FirePoint.position, Quaternion.identity);
               bull.GetComponent<Rigidbody>().AddForce(FirePoint.forward*3000);
                  //开枪
                  time = 0;
                  AudioSource.PlayClipAtPoint(fire,transform.position);
                  ShootScoreManager.insernt.ResetShootNum(1);
              }
          }
          else
          {
              time += Time.deltaTime;
          }
          //控制手枪旋转
          currentX = Input.mousePosition.x / Screen.width;
          currentY = Input.mousePosition.y / Screen.height;
          float xRo = -Mathf.Clamp(currentY * XMaxRotate, XMinRotate, XMaxRotate)+20;
          float yRo = Mathf.Clamp(currentX * YMaxRotate, YMinRotate, YMaxRotate) +120;
          transform.eulerAngles = new Vector3(xRo, yRo, 0);

      }
  }

}

